﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Http;
using System.Net.Http.Headers;
using XclusiveClient.Classes;

namespace XclusiveClient
{
    public partial class AddOrder : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnCreateOrder_Click(object sender, EventArgs e)
        {
            {
                HttpClient client = new HttpClient();

                client.BaseAddress = new Uri("http://localhost:3676/");

                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));

                var o = new Order()
                {
                    status = RdbStatus.SelectedItem.Text,
                    ship_date = calShipDate.SelectedDate.ToShortDateString(),
                    ship_time = ddlShipTime.SelectedItem.Text,
                    ship_type = ddlShipType.SelectedItem.Text,
                    address = tbxAddress.Text,
                    employeeID = ddlEmpID.SelectedItem.Text,
                    listID = Convert.ToInt32(ddlListID.SelectedItem.Text)
                };

                HttpResponseMessage response = client.PostAsJsonAsync("api/order", o).Result;
                if (response.IsSuccessStatusCode)
                {
                    // lblStatus.Text = "Order Successfully Created!" + "<br/>";
                    Response.Redirect("AddOrderSuccess.aspx");
                }
                else
                {
                    lblStatus.Text = "Unable to create the order. Error code: " + response.StatusCode + ", reason: " + response.ReasonPhrase.ToString() + "<br/>";
                }
            }
        }
    }
}